modelmenu: listen for toplevel changes on the attach widget
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 5 Jul 2012 14:49:39 +0000 (10:49 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Fri, 6 Jul 2012 15:14:15 +0000 (11:14 -0400)
commit5dbf3a576aab1bd33e6e08121690afefad19e50f
treee02f334e7fd3f421f89a6f6036c4553ba67a8ae9
parentf81bd6c52daf4e55e50b7efb4d039ef6b4ac3ce9
modelmenu: listen for toplevel changes on the attach widget

Right now, when we create a GtkModelMenu for a GMenuModel, we listen to
changes to the menu's attach-widget to detect when a toplevel
GtkApplicationWindow becomes available to fetch actions from it.

This unfortunately breaks this simple code:

  GtkWidget *application_window = gtk_application_window_new();
  GtkWidget *menu_button = gtk_menu_button_new();
  GMenuModel *menu_model = get_menu_model();

  gtk_menu_button_set_menu_model(menu_button, menu_model);
  gtk_container_add(GTK_CONTAINER(application_window), menu_button);

Since GtkMenuButton creates a GtkModelMenu and sets itself as its attach
widget before it's added to a hierarchy containing a
GtkApplicationWindow.

Fix the bug by simply listening for changes in the window hierarchy, and
creating the menu model when the attach widget is added to an
application window.

https://bugzilla.gnome.org/show_bug.cgi?id=679454
gtk/gtkmodelmenu.c